package com.hpjpw.idoapp.controller;

import com.hpjpw.ido.domain.TopicImg;
import com.hpjpw.ido.service.ITopicImgService;
import com.hpjpw.idoapp.service.IDoTopicService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api("")
@RestController
@RequestMapping("/ido/app/topicImg")
public class IDoTopicImgController {
    @Autowired
    ITopicImgService topicImgService;
    @Autowired
    IDoTopicService topicService;
    /**
     * 获取每周主题的图片详细信息
     */
    @GetMapping()
    @ApiOperation("获取当前使用的主题")
    public AjaxResult getTopicImgNow(){
        Map<String, String> map = topicService.selectTopicNow();
        /* 如果所有主题都不在当前时间使用 */
        if (StringUtils.isNull(map)){
            return AjaxResult.error("当前无主题可使用！");
        }
        TopicImg topicImg = new TopicImg();
        topicImg.setTopicId(Long.parseLong(map.get("topicId")));
        List<TopicImg> mapReturn = topicImgService.selectTopicImgList(topicImg);
        /* 主题没有描述图片时 */
        if (StringUtils.isNull(mapReturn)){
            return AjaxResult.error("当前无主题图片！");
        }
        return AjaxResult.success(mapReturn);
    }
}
